package com.sherlocky.common;

import javax.servlet.http.HttpServletRequest;

import conf.Constants;


public class SecurityContextHolder {
	/** 记录当前访问请求访问的上下文，因为不同用户可能访问的上下文不同 */
	private static ThreadLocal<String> contextPathHolder = new ThreadLocal<String>();
	
	/**
	 * 获取当前请求的上下文，以/结尾
	 * @return
	 */
	public static String getContextPath() {
		return contextPathHolder.get();
	}
	
	public static void setContextPath(HttpServletRequest request) {
		contextPathHolder.set(request.getScheme() 
				+ "://" + request.getServerName() 
				+ (request.getServerPort() == 80? "" : ":" + request.getServerPort()) 
				+ request.getContextPath()
				+ "/");
	}
	
	public static void clearContext() {
		contextPathHolder.remove();
	}
}
